// pages/component/homes/withdraw/withdraw.js
var GlobalData = require('../../../../utils/GlobalData.js');
var dataManager = require('../../../../utils/dataManager.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money: "",
    moneyall: 100,
    bindInfoData: { bankName: "请绑定银行卡", account: "", trueName: "", type: 0, img: "yhk" },
    state: false,
    type: 0

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    dataManager.removeBtnObserver("withdraw")
    if (GlobalData.withDrawType && GlobalData.withDrawType.type) {
      this.setData({
        bindInfoData: GlobalData.clone(GlobalData.withDrawType),
        state: true
      });
    }
    if (GlobalData.homeData) {
      let m = GlobalData.homeData.promotebalance;
      this.setData({
        moneyall: m
      })
    }
  },
  inputMoney: function (e) {
    var money = parseInt(e.detail.value);
    if (money == 0) {
      return "";
    }
    this.setData({
      money: money
    })
    // return money;

  },
  onWithDraw: function () {
    if (!this.data.money || this.data.money == "") {
      app.onshowModal("请输入您要提现的金额。");
      return;
    }
    if (this.data.money > GlobalData.homeData.promotebalance) {
      app.onshowModal("可提现余额(" + GlobalData.homeData.promotebalance + ")不足" + this.data.money);
      return;
    }
    if (this.data.bindInfoData.type == 1) {
      this.data.type = 2
    } else if (this.data.bindInfoData.type == 0) {
      app.onTip("请选择提现方式", "/pages/withdrawaloptions/withdrawaloptions", false);
      return;
    } else {
      this.data.type = 1;
      this.data.bindInfoData.bankName = "";
      this.data.bindInfoData.account = "";
    }
    // app.setOpenID("ok-oq5H_xjwEdYf8vkvo-PIsLjtc")
    // ok-oq5H_xjwEdYf8vkvo-PIsLjtc
    var data = { "method": "addwidthdrawal", "token": GlobalData.token, "type": this.data.type, "amount": this.data.money, "openid": app.getOpenID(), "source": "smapp", bankname: this.data.bindInfoData.bankName, truename: this.data.bindInfoData.trueName, account: this.data.bindInfoData.account }
    dataManager.OnRequestPost(data, this.onProcessData);
  },
  onProcessData: function (data) {
    this.setData({
      money: ""
    })
    if (this.data.type == 1) {
      let str = "请注意微信推送的红包，及时领取。";
      app.onTip(str, "/pages/component/homes/home/home", true);
    }
    else {
      app.onTip("提现成功。", "/pages/component/homes/home/home", true);
    }
  },
  bindBankCard: function () {
    // if (this.data.bindInfoData.type == 1) {
    dataManager.UseNavigateTo("/pages/withdrawaloptions/withdrawaloptions", false)
    // } else
    //   dataManager.UseNavigateTo("/pages/component/homes/bindbankcard/bindbankcard", false)
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})